package com.xiaoniu.mc.client.context;

import com.xiaoniu.mc.client.config.BaseProperties;
import com.xiaoniu.mc.client.handler.XmqMessageHook;
import com.xiaoniu.mc.client.producer.XmqProducer;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @类描述：
 * @创建人：林继丰
 * @创建时间：2017/8/17 18:45
 * @版权：Copyright (c) 深圳市牛鼎丰科技有限公司-版权所有.
 */
public class ApplicationContext {

    //topic对应消费者
    private static final ConcurrentHashMap<String, DefaultMQPushConsumer> topicMapConsumer = new ConcurrentHashMap<>();

    //topic对应处理者
    private static final ConcurrentHashMap<String, XmqMessageHook> topicMaphooks = new ConcurrentHashMap<>();

    //保存群组对应consumer配置信息
    private static final ConcurrentHashMap<String, String> groupNameMapMeta = new ConcurrentHashMap<>();

    //instanceName对应消费者名字
    private static final ConcurrentHashMap<String, XmqProducer> instanceNameMapProducer = new ConcurrentHashMap<>();

    private static volatile BaseProperties baseProperties;

    public static ConcurrentHashMap<String, DefaultMQPushConsumer> getTopicMapConsumer() {
        return topicMapConsumer;
    }

    public static ConcurrentHashMap<String, XmqMessageHook> getTopicMaphooks() {
        return topicMaphooks;
    }

    public static BaseProperties getBaseProperties() {
        return baseProperties;
    }

    public static ConcurrentHashMap<String, String> getGroupNameMapMeta() {
        return groupNameMapMeta;
    }

    public static void setBaseProperties(BaseProperties baseProperties) {
        ApplicationContext.baseProperties = baseProperties;
    }

    public static ConcurrentHashMap<String, XmqProducer> getInstanceNameMapProducer() {
        return instanceNameMapProducer;
    }
}
